/*
 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef WebView_h
#define WebView_h

#include "IntRect.h"
#include <wtf/PassRefPtr.h>
#include "wtf/text/WTFString.h"
#include <view/viewgroup.h>
#include "PlatformTouchEvent.h"

namespace WebCore {
class Frame;
class Page;
class FrameView;
class HTMLFrameOwnerElement;
class URL;
class ResourceRequest;
}

namespace WebKit{

class WebView :public cdroid::ViewGroup{
private:
    WTF::String m_ToolTip;
    WebCore::IntRect m_ToolTipArea;
    WebCore::IntSize m_ContentSize;
protected:
    bool onKeyUp(int,cdroid::KeyEvent&) override;
    bool onKeyDown(int,cdroid::KeyEvent&)override;
    bool onTouchEvent(cdroid::MotionEvent&)override;
    void onDraw(Canvas&)override;
    void onSizeChanged(int w,int h,int oldw,int oldh)override;
    WebCore::Page* m_page;
public:
    WebView(int w,int h);
    ~WebView();
    void setContentSize(int horz,int vert);
    int computeHorizontalScrollRange()override;
    int computeVerticalScrollRange()override;

    WebCore::Page* page() const { return m_page; }

    void loadUrl(const WTF::String& url);
    void load(const WebCore::ResourceRequest &request);
    void reload();
    void stop();
    void setToolTip(const WTF::String&);
    void setToolTipArea(const WebCore::IntRect&); 
    WebCore::Page*page(){return m_page;}

    void frameRect(WebCore::IntRect& rect) const;

    PassRefPtr<WebCore::Frame> createFrame(const WebCore::URL&, const WTF::String& name, WebCore::HTMLFrameOwnerElement*, 
        const WTF::String& referrer, bool allowScrolling, int marginWidth, int marginHeight, WebCore::Frame* parentFrame);

    // JavaScript Dialog
    void runJavaScriptAlert(const WTF::String& message);
    bool runJavaScriptConfirm(const WTF::String& message);
    bool runJavaScriptPrompt(const WTF::String& message, const WTF::String& defaultValue, WTF::String& result);
};
}//endof namespace
#endif // WebView_h
